<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="75px">
        <el-form-item label="活动日期" prop="activityDate">
          <el-date-picker clearable
            v-model="queryParams.activityDate"
            type="date"
            value-format="timestamp"
            placeholder="请选择活动日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="活动名称" prop="activityName">
          <el-input
            v-model="queryParams.activityName"
            placeholder="请输入活动名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="负责人" prop="leaderName">
          <el-input
            v-model="queryParams.leaderName"
            placeholder="请输入活动负责人"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-button @click="showTable1 = true"> 活动详情</el-button>
      <el-button @click="showTable2 = true">活动审批</el-button>
      <activities-info :showTable1="showTable1" :showTable2="showTable2" :list="activitiesList"></activities-info>

          
    </div>
  </template>
  
  <script>
  // 注册局部组件
  import activitiesInfo from "../../../components/business/activities/activitiesInfo.vue";
  // 引入方法
  import { listActivities, getActivities, delActivities, addActivities, updateActivities } from "@/api/business/activities";
  import { listElderlyapartment, getElderlyapartment, delElderlyapartment, addElderlyapartment, updateElderlyapartment } from "@/api/business/elderlyapartment";
  import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus, deptTreeSelect,commonUserList } from "@/api/system/user";
 
  
  export default {
    components: {
      activitiesInfo
    },
    name: "Activities",
    data() {
      return {
        showTable1: false,
        showTable2: false, // 当前激活的页签 
        IsAdd: true,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        activitiesList: [],
        // 公寓信息
        apartmentList: [],
        //普通用户list
        workUserList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          apartmentId: null,
          activityDate: null,
          activityTime: null,
          activityName: null,
          activityDescription: null,
          applyStatus:2,
          leaderName: null,
          participantCount: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          apartmentId: [
            { required: true, message: "公寓ID不能为空", trigger: "blur" }
          ],
          activityDate: [
            { required: true, message: "活动日期不能为空", trigger: "blur" }
          ],
          activityTime: [
            { required: true, message: "活动时间不能为空", trigger: "blur" }
          ],
          activityName: [
            { required: true, message: "活动名称不能为空", trigger: "blur" }
          ],
          leaderName: [
            { required: true, message: "活动负责人不能为空", trigger: "blur" }
          ],
        }
      };
    },
    created() {
      this.getList();
      this.getApartmentList();
      this.getCommonUserList();
    },
    methods: {
  
      getCommonUserList(){
        commonUserList().then(response =>{
          this.workUserList = response.rows
          console.log(this.workUserList);
        })
      },
      //获取公寓名称列表
      getApartmentList(){
        listElderlyapartment().then(response =>{
          this.apartmentList = response.result;
        });
        listUser().then(response =>{
          var list = [];
          //todo
          response.rows.filter((p)=>{
            if(p.deptId != 103 && p.deptId!=105){
              list.push(p);
            }
            console.log(list)
            return list
          })
          this.workUserList =  list
        })
      },
      /** 查询活动列表 */
      getList() {
        this.loading = true;
        listActivities(this.queryParams).then(response => {
          this.activitiesList = response.result;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          apartmentId: null,
          activityDate: null,
          activityTime: null,
          activityName: null,
          activityDescription: null,
          leaderName: null,
          participantCount: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加活动";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getActivities(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改【请填写功能名称】";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              this.from.createUserId = this.workUserList.createUserId
              updateActivities(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addActivities(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
          return delActivities(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('business/activities/export', {
          ...this.queryParams
        }, `activities_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
  
  <style scoped>
    .mb8{
      margin-right: 10px;
    }
    .act{
      margin-top: 5px;
    }
  </style>